package com.chennan.javabase.api.rest.controller;

import com.chennan.javabase.domain.map.ToMap;
import com.chennan.javabase.domain.map.modal.Product;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author chennan
 * @createTime 2021年07月26日 13:24:00
 */

@RestController
@Api("java基础演示")
@RequestMapping("/java")
public class MapController {

    @Autowired
    private ToMap toMap;

    @GetMapping("/to-map")
    public List<Object> toMap(){
        List<Product> products = toMap.getProducts(10);
        Map<BigDecimal, Product> collect = products.stream().collect(Collectors.toMap(Product::getId, a -> a));

        List<Object> list = new ArrayList<>();
        list.add(products);
        list.add(collect);
        return list;
    }


}
